﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreatePosition.aspx.cs"
    Inherits="ZX.WebApp.EditWidows.OrganizationalManager.CreatePosition" %>
                   <%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
   <style type="text/css">
        body
        {
            font-size: 14px;
        }
        .title2
        {
            font-weight: bold;
            font-size: 14px;
            text-align: center;
        }                                                                                               
    </style>
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link type="text/css" rel="stylesheet" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link href="../../Scripts/yui_2.9.0/build/treeview/assets/treeview-core.css" rel="stylesheet"
        type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <!-- Source files -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script src="../../Scripts/Public.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../../Scripts/CombinButton.js" type="text/javascript"></script>
    <link href="../../Styles/extendTable.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" action="../../Extend/AjaxData/DataProcessin.aspx" >
    <table class="tableContent">
        <tr>
            <td colspan="3" class="title2">
                <asp:Label ID="Lb_Title" runat="server"><span style="font-weight:bold">按职务类别设置职位</span> </asp:Label>
            </td>
        </tr>
        <tr>
            <td width="75px">
                &nbsp;上级职位：
            </td>
            <td colspan="2"><input type="hidden" id="ParentID" name="ParentID" runat="server" />
                    <input type="text" id="txtParentID" name="txtParentID" disabled="disabled"
                        runat="server" style="width: 78%; background: #e7eaf4;" />
                    <button id="btnParentID" style="width: 15%;"  name="p" type="button" runat="server" 
                       class="btnCheck">
                        选择</button></td>
        </tr></table><table class="tableContent"> 
        <tr>
            <td colspan="3">
                 &nbsp;请选择职务：
            </td>
        </tr>
        <tr valign="top">
            <td>
                  
                <cc1:TreeDuty ID="treeDiv1" runat="server" AllowCheck="true" ></cc1:TreeDuty>
            </td>
            <td valign="top" align="center" width="40px">
                <p>
                    <input onclick="MoveSelected();" type="button" value="选定"></p>
                
                <p>
                    <br>
                    <input onclick="cancelClick();" type="button" value="清除">
                    <br>
                </p>
            </td>
            <td width="120px;">
             	<select multiple="multiple" id="selectDuty" style="width: 100%;height:240px;">
		        </select>

            </td>
        </tr>
        

    </table>
    <div id="dialog1" class="yui-pe-content">
            <div class="hd">
                信息选择</div>
            <div class="bd"><input type="hidden" id="ID" runat="server" />
                <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                    margin: 0px; padding: 0px;"></iframe>
            </div>
        </div>
    </form>
    <form id="form2" action="../../Extend/AjaxData/DataProcessin.aspx">
        <textarea style="display: none" id="jsonDataContent" rows="2" cols="2" name="jsonDataContent"></textarea>
    </form>
</body>
<script type="text/javascript">
    var names;
    var id;
    var ids = "";
    function MoveSelected() { 
        var hiLit = tree1.getNodesByProperty('highlightState', 1);
        var labels = [];
        if (YAHOO.lang.isNull(hiLit)) {
            alert("没有选择任何项!");    
            return;
        } else {
            for (var i = 0; i < hiLit.length; i++) {
                var node = tree1.getTreeDefinition();
                id = hiLit[i].href.split("#@")[1]
                if (id!=undefined) {
                   MoveNode(hiLit[i].label, id)
                }
                //names = names + hiLit[i].label;
                
            }
        }
    }

    function MoveNode(text, id) {
        var flag = true;
        var selectDuty = document.getElementById("selectDuty")
        var length = selectDuty.options.length;

        for (var i = 0; i < length; i++) {
            if (selectDuty.options[i].value == id) {
                flag = false;
            }
        }
        if (id != "00000000-0000-0000-0000-000000000000" && flag == true) {
            selectDuty.options.add(new Option(text, id));
        }
    }
    function cancelClick() {
        var selectDuty = document.getElementById("selectDuty");
        if (selectDuty.selectedIndex != -1) {
            var length = selectDuty.options.length;
            for (var i = length - 1; i >= 0; i--) {
                if (selectDuty.options[i].selected == true) {
                    selectDuty.options.remove(i);

                }

            }
        }
    }
    var callback =
        {
            success: handleSuccess1,
            failure: handleFailure1,
            argument: { foo: "foo", bar: "bar" }
        };


    var handleSuccess1 = function (o) {
        alert("设置成功");
        //this.cancel();
    };
    var handleFailure1 = function (o) {
        alert("操作失败");
    };


    var Save = function (fkey) {
        if ($("#txtParentID").val() == "") {
            alert("请选择上级职位");
            return false;
        }
        else {
            $("#selectDuty option").each(function () {
                ids += $(this).val() + ",";
            });
            $("#jsonDataContent").val(ids);
            var formObject = document.getElementById('form2');
            YAHOO.util.Connect.setForm(formObject);
            var url = "../../Extend/AjaxData/DataProcessin.aspx?action=Save&entity=DatPost&r=" + Math.random() + "&parentID=" + $("#ParentID").val() + "&ids=" + ids + "&deptId=" + fkey + "";
            var request = YAHOO.util.Connect.asyncRequest('Post', url, callback);
            parent.Native("", fkey);
            alert("设置成功");
            return true;
        }
    }
</script>
<script type="text/javascript">

    //global variable to allow console inspection of tree:
    var tree1;           
    //anonymous function wraps the remainder of the logic:
    (function () {   
        var makeBranch = function (parent, label) {

        }

        var treeInit = function () {
            tree1 = new YAHOO.widget.TreeView("treeDiv1");
            makeBranch(tree1.getRoot());
            tree1.setNodesProperty('propagateHighlightUp', true);
            tree1.setNodesProperty('propagateHighlightDown', true);
            tree1.subscribe('clickEvent', tree1.onEventToggleHighlight);
            tree1.render();
        }
        function checkNode(areaIds) {   
            var topNodes = tree1._nodes;                
            for (var i = 1; i < topNodes.length; ++i) {
                var id = topNodes[i].href.split("#@")[1];
                if (areaIds.indexOf(id) > -1) {
                    //for (var node in topNodes) {
                    topNodes[i].highlightState = 0; // setNodesByProperty('highlightState');
                }
            }
        };
        var request = "../../Extend/AjaxData/DataProcessin.aspx?action=Get&entity=DatPost&condition&deptId=" + getPar1('id') + "";
        YAHOO.util.Connect.asyncRequest('POST', request, {
            success: function (res) {
                var inventory;
                try {     
                    var str = res.responseText;
                    checkNode(str);
                    //inventory = JSON.parse(res.responseText);
                    //alert(inventory);
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
              alert("读取菜单数据错误：" + error.statusText);
            }
        }, null);
        //Add an onDOMReady handler to build the tree when the document is ready
        YAHOO.util.Event.onDOMReady(treeInit);

    })();
    /*客户选择对应的方法和ID*/
    var _fn, _id;
    function ShowDialog(fn, id, src) {
        _fn = fn;
        _id = id;
        document.getElementById("EditUIWindow1").src = src;
        YAHOO.example.container.dialog1.show();
    }
    YAHOO.namespace("example.container");
    YAHOO.util.Event.onDOMReady(function () {
        var handleSubmit = function () {
            var editwindow = document.getElementById("EditUIWindow1");
            if (editwindow) {
                editwindow.contentWindow.ChooseInfo();
            }
            YAHOO.example.container.dialog1.hide();
        };
        var handleCancel = function () {
            this.cancel();
        };
        var handleSuccess = function (o) {
            var response = o.responseText;
            response = response.split("<!")[0];
            document.getElementById("resp").innerHTML = response;
        };
        var handleFailure = function (o) {
            alert("Submission failed: " + o.status);
        };
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
					            { width: "400px",
					                height: "400px",
					                fixedcenter: true,
					                visible: false,
					                draggable: true,
					                close: true,
					                autofillheight: "body",
					                constraintoviewport: true,
					                buttons: [{ text: "确定", handler: handleSubmit, isDefault: true },
								            { text: "取消", handler: handleCancel}]
					            });
        YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };
        YAHOO.example.container.dialog1.render();
    });
</script>
</html>